#pragma once
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <vector>
void SetNonBlock(int sock)
{
    int f1 = fcntl(sock,F_GETFL);
    if(f1<0)
    {
        std::cerr << "fcntl failed" <<std::endl;
    }
    fcntl(sock,F_SETFL, f1 | O_NONBLOCK );
}

void SplitSegment(std::string& inbuffer,std::vector<std::string>* tokens,const std::string& sep)
{
    while(true)
    {
        std::cout << "inbuffer: " << inbuffer << std::endl;
        auto pos = inbuffer.find(sep);
        if(pos ==std::string::npos)
        {
            break;
        }
        std::string sub = inbuffer.substr(0,pos);
        tokens->push_back(sub);
        inbuffer.erase(0,pos+sep.size());
    }
}

bool Deserialize(std::string& seg,std::string* out1,std::string* out2)
{
    std::string op = "+";
    auto pos = seg.find(op);
    if(pos == std::string::npos) 
        return false;
    *out1 = seg.substr(0,pos);
    *out2 = seg.substr(pos+op.size());
    return true;
}